package hah;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;

public class Tranpose {
    public int[][] transpose(int[][] matrix){
            int rowlen=matrix.length;
            int collen= matrix[0].length;
            int[][] result=new int[collen][rowlen];
            for (int i=0;i<collen;i++){
                for (int j=0;j<rowlen;j++){
                    result[i][j]= matrix[j][i];
                }
            }
            return result;

    }
    HashSet<Integer> set=new HashSet<Integer>();
    public int singleNumber(int[] nums) {
        for (int i=0;i<=nums.length-1;i++){
            if (!set.contains(nums[i])){
                set.add(nums[i]);
            }else {
                set.remove(nums[i]);
            }
        }
        return set.iterator().next();
    }
    public int singleNumber2(int[] nums) {
        int res=0;
        for (int i=0;i<nums.length;i++){
            res=res^nums[i];
        }
        return res;
    }
    //颠倒二进制位
    public int reverseBits(int n) {
        int res=0;
        for (int i=0;i<32&&n!=0;i++){
            res|=(n&1)<<(31-i);
            n>>>=1;
        }
        return res;
    }
}
